package curator.demo;

import com.qs.zk.utils.CuratorClientUtils;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.recipes.leader.LeaderSelector;
import org.apache.curator.framework.recipes.leader.LeaderSelectorListenerAdapter;

public class MaterSelector {

    private static String master_path = "/testSelector";


    public static void main(String[] args) throws InterruptedException {
        CuratorFramework client = CuratorClientUtils.getInstance();
        LeaderSelector selector = new LeaderSelector(client, master_path, new LeaderSelectorListenerAdapter() {
            @Override
            public void takeLeadership(CuratorFramework client) throws Exception {
                System.out.println("-->>称为master角色");
                Thread.sleep(3000);
                System.out.println("--->>完成master操作，释放master权利。");
            }
        });

        selector.autoRequeue();
        selector.start();
        Thread.sleep(Integer.MAX_VALUE);
    }
}
